package com.yyjj.zixun.fragmnet;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.aries.ui.view.title.TitleBarView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.zixun.R;
import com.yyjj.zixun.adapter.GanTouAdapter;
import com.yyjj.zixun.adapter.ZiXunListAdapter;
import com.yyjj.zixun.api.Api;
import com.yyjj.zixun.entity.BaseGHResp;
import com.yyjj.zixun.entity.BiZiXunEntity;
import com.yyjj.zixun.entity.GtDataResp;
import com.yyjj.zixun.entity.NewsListEntity;
import com.yyjj.zixun.entity.TouJiaoGanHuoEntity;

import java.util.ArrayList;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseFragment;
import tech.com.commoncore.base.BaseRefreshLoadFragment;
import tech.com.commoncore.base.BaseTitleFragment;
import tech.com.commoncore.base.BaseTitleRefreshLoadFragment;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.entity.BaseTResp;


public class GanTouFragment extends BaseFragment {
    GanTouAdapter adapter;
    private RecyclerView recyclerView;

    SmartRefreshLayout smartLayout_rootFastLib;

    public static GanTouFragment newInstance() {
        Bundle args = new Bundle();

        GanTouFragment fragment = new GanTouFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getContentLayout() {
        return R.layout.zixun_guantou_fragment;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        smartLayout_rootFastLib = mContentView.findViewById(R.id.smartLayout_rootFastLib);
        recyclerView = mContentView.findViewById(R.id.rv_contentFastLib);
        adapter = new GanTouAdapter(R.layout.zixun_item_gantou_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(adapter);



        smartLayout_rootFastLib.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                requestData();
            }
        });

        smartLayout_rootFastLib.autoRefresh();


    }

    private void requestData() {
        ViseHttp.GET(Api.B_ZIXUN)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("page", 1 + "")
                .addParam("type", "chjdd")
                .request(new ACallback<BaseGHResp<ArrayList<BiZiXunEntity>>>() {
                    @Override
                    public void onSuccess(BaseGHResp<ArrayList<BiZiXunEntity>> data) {
                        if (data.code ==1 && data.data !=null){
                            if (data.data.size()>=5){
                                adapter.setNewData(data.data.subList(0,5));
                            }else {
                                adapter.setNewData(data.data);
                            }

                        }
                        smartLayout_rootFastLib.finishRefresh();
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                    }
                });
    }


}
